package Controllers;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import Bean.BeanUser;
import Impl.UserServiceImpl;
@Controller
public class UserModifyController extends HttpServlet {
	private static final long serialVersionUID = 1L;
    UserServiceImpl userService;
	 @RequestMapping(value = "/UserModify", method = RequestMethod.POST)
		@ResponseBody
		public JSONObject userRegister(HttpServletRequest request,@RequestBody JSONObject in) throws Exception {
		 	ApplicationContext applicationContext=(ApplicationContext)request.getSession().getServletContext().getAttribute("ctx");
	        userService=(UserServiceImpl)applicationContext.getBean("UserServiceImpl");
			JSONObject obj = new JSONObject();
			BeanUser user = new BeanUser();
			user.setUser_id(in.getString("userid"));
			user.setUser_name(in.getString("username"));
			user.setPwd(in.getString("pwd"));
			userService.userupdate(user.getUser_id(), user.getPwd(), user.getUser_name());		
			obj.put("status", "OK");
			return obj;
		}
}
